package question_service

import (
	"peilian-api/app/global/databases/tables"
	"peilian-api/app/global/errors"
	"peilian-api/app/global/variable"

	"github.com/gin-gonic/gin"
)

type QuesResp struct {
	Id   uint   `json:"id"`
	Name string `json:"name"`
}

func GetQuestion(ctx *gin.Context) (*[]QuesResp, *errors.ErrRes) {
	var question []tables.Question
	err := variable.DB.MySQL.Find(&question).Where("questionType = 2 and status = 0").Error
	if err != nil {
		return nil, errors.NewErrInfo(30001, err)
	}
	out := make([]QuesResp, 0)
	for i := 0; i < len(question); i++ {
		var ques QuesResp
		ques.Id = question[i].ID
		ques.Name = question[i].Text
		out = append(out, ques)
	}
	return &out, nil
}
